package com.yoo.ons.dialog

import android.graphics.Color
import android.view.animation.AnimationUtils
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import com.yoo.module_base.utils.setOnClickCallback
import com.yoo.module_base.utils.setSystemBottomNavBarColor
import com.yoo.module_base.utils.setSystemBottomNavBarNoColor
import com.yoo.module_base.view.tag.CustomTagCloudView
import com.yoo.module_base.view.tag.TagModel
import com.yoo.ons.R
import com.yoo.ons.ToastUtil
import razerdp.basepopup.BasePopupWindow

class UpdateMyInterestsPopup(activity: FragmentActivity, var list:ArrayList<TagModel>, var callBack:(list:ArrayList<TagModel>)->Unit):BasePopupWindow(activity) {
    init {
        setContentView(R.layout.popup_update_my_interests)
        initView(activity)
        showAnimation=  AnimationUtils.loadAnimation(activity, com.yoo.module_res.R.anim.anims_slide_in_bottom)
        dismissAnimation=  AnimationUtils.loadAnimation(activity, com.yoo.module_res.R.anim.anims_slide_out_bottom)
    }

    fun initView(activity:FragmentActivity){
        val popupClose = findViewById<ImageView>(R.id.popup_close)
        val popupSelectList = findViewById<CustomTagCloudView>(R.id.popup_interests_tag)
        val popupUpdateInterestSave = findViewById<TextView>(R.id.popup_update_interest_save)
        popupClose.setOnClickCallback {
            dismiss()
        }
        popupSelectList.setTagBeans(list)
        popupSelectList.setOnTagClickListener {
            if (!list[it].check) {
                var count = 0
                for (i in 0 until list.size) {
                    if (list[i].check) {
                        count++
                    }
                }
                if (count >= 8) {
                    ToastUtil.showToast(activity.getString(com.yoo.module_res.R.string.interest_more_select_tip))
                    return@setOnTagClickListener
                }
            }

            list[it].check = !list[it].check
            popupSelectList.getTags(
                it,
                if (list[it].check) Color.parseColor("#E2449D") else Color.WHITE,
                if (list[it].check) com.yoo.module_res.R.drawable.shape_update_info_bg else com.yoo.module_res.R.drawable.shape_solid_771b96_radius_26
            )
        }

        popupUpdateInterestSave.setOnClickCallback {
            callBack.invoke(list)
            dismiss()
        }



        //设置底部导航栏颜色
        setSystemBottomNavBarColor(activity)
        onDismissListener =object : OnDismissListener() {
            override fun onDismiss() {
                setSystemBottomNavBarNoColor(activity)
            }

        }
    }
}